package com.titan.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.*;

/**
 * Entity implementation class for Entity: Cabin
 *
 */
@Entity
@Table(name="Reservation")
public class Reservation implements Serializable {

	private static final long serialVersionUID = 1L;

	private int id;
	private float amountPaid;
	private Date date;
	private Cruise cruise;
	private Set<Customer> customers = new HashSet<Customer>();
	private Set<Cabin> cabins=new HashSet<Cabin>();
	
	@ManyToMany(cascade={CascadeType.ALL})
	@JoinTable(name="RESERVATION_CABIN",
			   joinColumns={@JoinColumn(name="RESERVATION_ID")},
			   inverseJoinColumns={@JoinColumn(name="CABIN_ID")})
	public Set<Cabin> getCabins() {
		return cabins;
	}
	public void setCabins(Set<Cabin> cabins) {
		this.cabins = cabins;
	}
	@ManyToMany
	@OrderBy("lastName ASC")
	@JoinTable(name="RESERVATION_CUSTOMER",
			   joinColumns={@JoinColumn(name="RESERVATION_ID")},
			   inverseJoinColumns={@JoinColumn(name="LASTNAME"),@JoinColumn(name="SSN")})
	public Set<Customer> getCustomers() {
		return customers;
	}
	public void setCustomers(Set<Customer> customers) {
		this.customers = customers;
	}
	@TableGenerator(name="RESERVATION_GENERATOR",
			table="GENERATOR_TABLE",
			pkColumnName="PRIMARY_KEY_COLUMN",
			valueColumnName="VALUE_COLUMN",
			pkColumnValue="RESERVATION_ID",
			allocationSize=5)
	
	@Id
	@GeneratedValue(strategy=GenerationType.TABLE,generator="RESERVATION_GENERATOR")
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	@Column(name="AMOUNT_PAID")
	public float getAmountPaid() {
		return amountPaid;
	}
	public void setAmountPaid(float amountPaid) {
		this.amountPaid = amountPaid;
	}
	
	@Column(name="DATE_RESERVED")
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	
	@ManyToOne
	@JoinColumn(name="CRUISE_ID")
	public Cruise getCruise() {
		return cruise;
	}
	public void setCruise(Cruise cruise) {
		this.cruise = cruise;
	}
	
	@PrePersist void prePersist(){
		System.out.println("Reservation is preprocessed");
	}
	
	@PostPersist void postPersist(){
		System.out.println("Reservation is persisted");
	}
	
}
